package br.com.cast.scc.service;

import java.util.Iterator;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import br.com.cast.scc.dao.VeiculoDAO;
import br.com.cast.scc.enums.StatusRegistroAtivo;
import br.com.cast.scc.model.Veiculo;
import br.com.cast.scc.veiculo.FiltroPesquisaVeiculos;

@Component
public class VeiculoServiceImpl implements VeiculoService {

	@Autowired
	private VeiculoDAO veiculoDAO;
	
	@Override
	public long total() {
		return veiculoDAO.total(Veiculo.class);
	}

	@Transactional
	@Override
	public void salvar(Veiculo veiculo) {
		if(veiculo.getCodigo()== null){
			veiculo.setStatus(StatusRegistroAtivo.ATIVO.getSituacao());
			veiculoDAO.salvar(veiculo);
		}else{
			veiculoDAO.alterar(veiculo);
		}

	}
	
	
	@Override
	public Iterator<? extends Veiculo> consultaPaginada(long inicio,
			long total, FiltroPesquisaVeiculos filtro) {
		return veiculoDAO.consultaPaginada(inicio, total, filtro);
	}

	

}
